import mockRequest from '@/utils/mockRequest'

const actions = {
    // 发送获取mock的主页数据的action
    async getHomeList({commit}) {
        const result = await mockRequest.get('/home')
        if (result.code === 200) {
            commit('GETHOMELIST', result.data)
        }
    }
}
const mutations = {
    GETHOMELIST(state, homeList) {
        state.homeList = homeList
    }
}
const state = {
    homeList: {}
}
const getters = {
    // 销售额柱状图横坐标
    orderFullYearAxis(state) {
        return state.homeList.orderFullYearAxis || []
    },
    // 销售额柱状图纵坐标
    orderFullYear(state) {
        return state.homeList.orderFullYear || []
    },
    // 销售额排行榜
    orderRank(state) {
        return state.homeList.orderRank
    },
    // 访问量柱状图横坐标
    userFullYearAxis(state) {
        return state.homeList.userFullYearAxis || []
    },
    // 访问量柱状图纵坐标
    userFullYear(state) {
        return state.homeList.userFullYear || []
    },
    // 访问量排行榜
    userRank(state) {
        return state.homeList.userRank || []
    },
    // 支付笔数柱状图数据
    payTrend(state) {
        return state.homeList.payTrend || []
    },
    // 搜索排行表格数据
    searchWord(state) {
        return state.homeList.searchWord || []
    },
    // 饼图展示的数据
    saleRank(state) {
        return state.homeList.saleRank || {}
    }

}

export default {
    namespaced: true,
    actions,
    mutations,
    state,
    getters
}